package com.dog.modules.websocket.config;


import com.dog.modules.websocket.config.Interceptor.AuthenticationInterceptor;
import com.dog.modules.websocket.handler.AppSSHSocketHandler;
import com.dog.modules.websocket.handler.BizSSHSocketHandler;
import com.dog.modules.websocket.handler.OpSSHSocketHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * WebSocket配置
 */
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Autowired
    OpSSHSocketHandler opSSHSocketHandler;
    @Autowired
    BizSSHSocketHandler bizSSHSocketHandler;
    @Autowired
    AppSSHSocketHandler appSSHSocketHandler;

    @Autowired
    AuthenticationInterceptor authenticationInterceptor;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
        webSocketHandlerRegistry
                .addHandler(opSSHSocketHandler, "/op")
                .addHandler(bizSSHSocketHandler, "/biz")
                .addHandler(appSSHSocketHandler, "/app")
                .addInterceptors(authenticationInterceptor)
                .setAllowedOrigins("*");
    }
}
